<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>弹出输入框</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>

    <style type="text/css">
        body {
            background-color: transparent;
            height: auto;
        }

        .confirm {
            width: 70px;
            text-align: center;
            position: fixed;
            top: 0;
            right: 0;
            height: 40px;
            line-height: 40px;
        }

        input {
            /*margin-top: 15px;*/
        }

        .bodyLayer {
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: rgba(0, 0, 0, .3);

        }

        .divInput input {
            width: 100%;
        }
    </style>
</head>
<body>
<div class="bodyLayer" tapmode onclick="cancel()">

</div>


<div class="myBtn  confirm  aui-col-xs-3" tapmode onclick="sure()">确定</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/myInfo.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/echo.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var orderId, UIInput, systemType;
    var placeHolderText, inputType, type;//提示信息，input类型
    var valueText = "";
    apiready = function () {
        api.parseTapmode();
        UIInput = api.require('UIInput');
        orderId = api.pageParam.orderId;
        pageType = api.pageParam.pageType;
        systemType = api.systemType;
        type = api.pageParam.type;//发布规格传过来的类别

        statusbarHeight=api.systemType=='ios'?20.0:0.0;
        $(".confirm").css({"top":statusbarHeight})
        initPage();
    }

    function initPage() {
        switch (pageType) {
            case "sendProduct":
                placeHolderText = "请输入快递号";
                inputType = "number";
                break;
            case "releaseFormat":
                placeHolderText = type == "color" ? "请输入自定义颜色" : "请输入自定义尺寸";
                inputType = "text";
                break;

        }
        UIInput.open({
            rect: {
                x: 0,
                y: statusbarHeight,
                w: api.winWidth - 70,
                h: 40
            },
            styles: {
                bgColor: '#fff',
                size: 14,
                color: '#000',
                placeholder: {
                    color: '#ccc'
                }
            },
            autoFocus: true,
            maxRows: 1,
            placeholder: placeHolderText,
            keyboardType: inputType,
            fixedOn: api.frameName
        }, function (ret, err) {
            if (ret) {
                inputId = ret.id;
            } else {

            }
        });

    }
    // 设置属性
    function sure() {

        UIInput.value(function (ret, err) {
            if (ret) {
                valueText = ret.msg;
                if (valueText.trim() != "") {
                    switch (pageType) {
                        case "sendProduct":
                            sendProductNo();
                            break;
                        case "releaseFormat":
                            addReleaseFormat();
                            break;

                    }
                } else {
                    api.toast({
                        msg: "请输入",
                        duration: 2000
                    })
                }
            }
        });
    }
    //发货输入订单号
    function sendProductNo() {
        //获取输入框的值
        showLoading();
        var data = {};
        data["orderId"] = orderId;
        data["sendNo"] = valueText;
        var url = 'Order/orderDelivery';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                api.toast({
                    msg: "发货成功",
                    duration: 2000,
                    location: 'bottom'
                })
                cancel();
                updateOrderNum();
                hideLoading();
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }
    //发布商品时候添加的规格
    function addReleaseFormat() {
        if(valueText.length>15){
            api.toast({
                msg: "不能超过十五个字",
                duration: 2000,
                location: 'bottom'
            })
            return false;
        }
        api.sendEvent({
            name: 'addReleaseFormat',
            extra: {
                releaseFormatValue: valueText
            }
        });
        cancel();
    }

    //取消
    function cancel() {
        api.closeFrame();
    }
</script>
</html>